package com.schedule.controller;


import com.schedule.pojo.RespBean;
import com.schedule.pojo.Yard;
import com.schedule.service.IYardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author star
 * @since 2022-02-11
 */
@RestController
@RequestMapping("/yard")
public class YardController {

    @Autowired
    private IYardService yardService;

    @ApiOperation(value="获取所有的场地信息")
    @GetMapping("/")
    public List<Yard> getAllYard(){
        return yardService.list();
    }

    @ApiOperation(value="添加场地信息")
    @PostMapping("/")
    public RespBean addYard(@RequestBody Yard yard){
        if(yardService.save(yard)){
            return RespBean.success("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    @ApiOperation(value = "更新场地信息")
    @PutMapping("/")
    public RespBean updateYard(@RequestBody Yard yard){
        if(yardService.updateById(yard)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    @ApiOperation(value = "删除场地信息")
    @DeleteMapping("/{id}")
    public RespBean deleteYard(@PathVariable Integer id){
        if(yardService.removeById(id)){
            return RespBean.success("删除成功！");
        }
        return RespBean.error("删除失败！");
    }

    @ApiOperation(value = "批量删除场地信息")
    @DeleteMapping("/")
    public RespBean deleteYardByIds( Integer[] ids){
        if(yardService.removeByIds(Arrays.asList(ids))){
            return RespBean.success("删除成功！");
        }
        return RespBean.error("删除失败！");
    }
}
